package log

import (
	"fmt"
	"strings"
)

// Level 日志级别
type Level uint8

const (
	LevelPanic Level = iota
	LevelFatal
	LevelError
	LevelWarn
	LevelInfo
	LevelDebug
)

// ParseLevel takes a string level and returns the log level constant.
func ParseLevel(lvl string) (Level, error) {
	switch strings.ToLower(lvl) {
	case "panic":
		return LevelPanic, nil
	case "fatal":
		return LevelFatal, nil
	case "error":
		return LevelError, nil
	case "warn", "warning":
		return LevelWarn, nil
	case "info":
		return LevelInfo, nil
	case "debug":
		return LevelDebug, nil
	}
	var l Level
	return l, fmt.Errorf("not a valid Level: %q", lvl)
}

type Logger interface {
	Debug(...interface{})
	Info(...interface{})
	Warn(...interface{})
	Error(...interface{})
	// Fatal 打印该日志之后程序会退出，生产环境不要使用
	Fatal(...interface{})
	// Panic 打印该日志之后会抛出panic异常，生产环境要recover()捕获一下
	Panic(...interface{})
	Debugf(string, ...interface{})
	Infof(string, ...interface{})
	Warnf(string, ...interface{})
	Errorf(string, ...interface{})
	// Fatalf 打印该日志之后程序会退出，生产环境不要使用
	Fatalf(string, ...interface{})
	// Panicf 打印该日志之后会抛出panic异常，生产环境要recover()捕获一下
	Panicf(string, ...interface{})
	Debugw(string, map[string]interface{})
	Infow(string, map[string]interface{})
	Warnw(string, map[string]interface{})
	Errorw(string, map[string]interface{})
	Fatalw(string, map[string]interface{})
	Panicw(string, map[string]interface{})
	Log(Level, ...interface{})
	Logf(Level, string, ...interface{})
	Logw(Level, string, map[string]interface{})
	Sync()
}
